/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2023-11-24 13:56:54
 * @LastEditors: zhangguliu1234 984556209@.com
 * @LastEditTime: 2024-01-24 10:35:09
 * @FilePath: \BED\components\my_wss.h
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
 */
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "cJSON.h"
#include "mqtt_client.h"

typedef struct CJsonStruct
{
    char *deviceType;
    char *subType;
    char *deviceMAC; // mac地址
    char *groupId;
    char *familyId;
    char *operate; // 命令
    char *type;    // 命令类型
    char *sub_type;
    char *sub_operate;
    char *msg;
    char *code;
    char *timeStr;
    char *sub_timestamp;
    char *source;
    char *version;
    char *timestamp; // 时间戳
    char *sign;
    char *append;
    char *mode;
    char *sub_mode;
    char *inaccuracie; // 误差值
    char *interval;    // 间隔时间
    // char *Bed_Write_State; // 写指令功能位
    char *left_uptemp;
    char *right_uptemp;
    char *left_downtemp;
    char *right_downtemp;
    char *left_VibFreq; // 左律动频率
    char *left_VibInt;  // 左律动强度
    char *right_VibFreq;
    char *right_VibInt;
    char *left_upkey;
    char *right_upkey;
    char *cost; // 付费状态
    char *left_downkey;
    char *right_downkey;
    char *sub_date; // 年月日
    char *sub_time; // 具体时间
    char *sub_week; // 一周
    char *sub_deviceType;
    char *sub_deviceId;
    char *sub_policyEn; // 策略开关
    char *sub_policyEnType;
    char *sub_downloadLink; // ota升级链接
    char *bed_key;
    char *left_mode;
    char *right_mode;
    char *left_temp;
    char *right_temp;
    char *left_time;
    char *right_time;
    char *LED;
} myCJson;

extern char mac_str[13];
extern esp_mqtt_client_handle_t my_client;
extern char subscribe_topic[100];
extern char g_publish_topic[100];
extern int Subscribe_End;
extern int First_Read;
extern myCJson cjson_data;
extern char Json_Append[20];
void mqtt_app_start(void);
cJSON *getObjectvalue(cJSON *root, const char *objectName);
void packet_subscribe_topic(char *paket_data);
void packet_publish_topic(char *paket_data);
int get_first_jsondata(cJSON *rx_json, myCJson *data);
void Publish_First_Connet(esp_mqtt_client_handle_t *client);
void Get_system_time(uint64_t *timestamp, myCJson *data);
int Parse_JsonData(cJSON *rx_json, myCJson *data);
void Run_JsonData(esp_mqtt_client_handle_t *client, char *topic, myCJson *data);
int safe_atoi(const char *str);
